import { ILoadMapTypeAll } from '@/common';
import { ManageCommonAPI } from '@/pages/type';
import { getSelectDataMapList, getTenantID } from '@/utils';
import { useEffect, useState } from 'react';
import { getStorageTreeService } from '../../Assetmanagement/AssetAllot/services';

/** 资产列表搜索 */
const getAssetSearchList = (loadInfo: Record<string, any>): ManageCommonAPI.ISearchList => {
  /**资产分类数据字典*/
  // const materialTypeMapList = loadInfo?.loadMapInfo?.[`${getTenantID()}${ILoadMapTypeAll.MATERIAL_TYPE}`];
  const materialTypeMapList = getSelectDataMapList(loadInfo?.loadMapInfo?.[`${getTenantID()}${ILoadMapTypeAll.MATERIAL_TYPE}`], 'name', 'id', true);

  /**资产状态数据字典*/
  const assetState = getSelectDataMapList(loadInfo?.loadMapInfo?.[`${getTenantID()}${ILoadMapTypeAll.ASSET_STATUS}`], 'name', 'id');

  /** 仓库树数据 */
  const [storageList, setStorageList] = useState<any>([]);

  /** 获取仓库树回调 */
  const updataGetStorage = (res: any) => {
    if (res && res?.msgFlag) {
      setStorageList(res?.obj);
    }
  };

  /** 获取仓库树 */
  const { getStorageLoading, getStorageRun } = getStorageTreeService(updataGetStorage, loadInfo?.curRes);

  useEffect(() => {
    getStorageRun();
  }, []);

  return [
    {
      name: 'assetName',
      placeholder: '资产名称',
      label: '资产名称',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'assetCode',
      placeholder: '资产编号',
      label: '资产编号',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'assetClass',
      placeholder: '资产分类',
      label: '资产分类',
      componentType: 'TreeSelect',
      dataSource: materialTypeMapList,
      allowClear: true,
      showSearch: true,
      treeNodeFilterProp: 'name',
      md: 4,
      sm: 24,
      whetherSenior: false,
      fieldNames: {
        label: 'name',
        value: 'id',
        children: 'children',
      },
    },
    {
      name: 'brandType',
      placeholder: '品牌',
      label: '品牌',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'paramsInfo',
      placeholder: '规格型号',
      label: '规格型号',
      componentType: 'Input',
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'assetState',
      placeholder: '资产状态',
      label: '资产状态',
      componentType: 'Select',
      dataSource: assetState,
      allowClear: true,
      md: 4,
      sm: 24,
      whetherSenior: false,
    },
    // {
    //   name: 'assetStoreId',
    //   placeholder: '所属仓库',
    //   label: '所属仓库',
    //   componentType: 'TreeSelect',
    //   dataSource: storageList,
    //   allowClear: true,
    //   md: 4,
    //   sm: 36,
    //   whetherSenior: false,
    //   fieldNames: {
    //     label: 'storeName',
    //     value: 'id',
    //     children: 'children',
    //   },
    // },
  ];
};

export { getAssetSearchList };
